<template>
	<view>
		
		<view class="foot">
			<view class="show">
				<view style="font-size: 36upx;font-weight: 555;padding: 0 30upx;">
					开票信息
				</view>
				<view class="same" style="border-bottom: 1upx solid #dddddd;">
					<view class="name">企业名称</view>
					<input class="uni-input uni-input_cell" type="text" placeholder="请填写'企业'名称" v-model="company_name"/>
				</view>
				<view style="font-size: 32upx;font-weight: 555;padding: 0 30upx;height: 80upx;line-height: 80upx;">
					收票人信息
				</view>
				<view class="same">
					<view class="name">纳税识别码*</view>
					<input class="uni-input uni-input_cell" type="text" placeholder="请输入纳税识别码" v-model="tax_number" />
				</view>
				<view class="same">
					<view class="name">注册地址*</view>
					<input class="uni-input uni-input_cell" type="text" placeholder="请输入注册地址" v-model="company_address" />
				</view>
				<view class="same">
					<view class="name">开户银行*</view>
					<input class="uni-input uni-input_cell" type="text" placeholder="请输入开户银行" v-model="bank" />
				</view>
				<view class="same">
					<view class="name">银行账号*</view>
					<input class="uni-input uni-input_cell" type="number" placeholder="请输入银行账号" v-model="bankNumber" />
				</view>
				<view class="same" style="">
					<view class="name">注册电话*</view>
					<input class="uni-input uni-input_cell" type="number" placeholder="请输入注册电话" v-model="company_phone" />
				</view>
				
				
			</view>
			<button v-if="show_hide== true" @click="submit" type="default" style="background-color: #000;color: #fff;width: 550upx;position: fixed;bottom: 100upx;left: 50%;transform: translate(-50%, -50%);">提交</button>
			<button v-if="show_hide== false" type="default" style="background-color: #000;color: #fff;width: 550upx;position: fixed;bottom: 100upx;left: 50%;transform: translate(-50%, -50%);" @click="edit" >提交编辑</button>
		</view>
		 
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
				res: [],
				user_id: '',
				id:'',
				company_name:'',
				tax_number: '',
				company_phone: '',
				bank: '',
				bankNumber: '',
				company_address: '',
				show_hide: true
			};
		},
		onLoad:function(e){
			if(e.id) {
				this.id = e.id
				this.show_hide = false
				this.setAjax()
			}
			uni.getStorage({
				key: 'user_id',
				success: (res) => {
					this.user_id = res.data
				},
			});
		},
		methods:{
			setAjax(){
				var o = this
				uni.request({
					url: 'https://cx.mingmeijt.com/Api/Tax/index',
					method: 'POST',
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					data:{
						user_id: this.user_id,
						session_id: uni.getStorageSync("sessionid")
					},
					success: res => {
						if(res.data.code == 999){
							uni.navigateTo({
								url:'/pages/999/999'
							})
						};
						if(res.data.code == 998){
							uni.navigateTo({
								url:'/pages/login/login'
							})
						}
						let obj = res.data.data
						let arr = obj.filter(function(item){
							return(item.id == o.id)
						})
						this.company_name = arr[0].company_name
						this.tax_number = arr[0].tax_number
						this.company_phone = arr[0].company_phone
						this.bank = arr[0].bank
						this.bankNumber = arr[0].bankNumber
						this.company_address = arr[0].company_address
					},
					fail: () => {},
					complete: () => {}
				});
			},
			submit() {
				uni.request({
					url: 'https://cx.mingmeijt.com/Api/Tax/addTax',
					method: 'POST',
					data: {
						user_id: this.user_id,
						// id: this.id,
						company_name: this.company_name,
						tax_number: this.tax_number,
						company_phone: this.company_phone,
						bank: this.bank,
						bankNumber: this.bankNumber,
						company_address: this.company_address,
						session_id: uni.getStorageSync("sessionid")
					},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						if(res.data.code == 999){
							uni.navigateTo({
								url:'/pages/999/999'
							})
						};
						console.log(res)
						uni.showToast({
							title: res.data.msg
						})
						if (res.data.code == 200) {
							setTimeout(function() {
								uni.reLaunch({
									url: '../../../pages/user/user'
								})
							}, 1200);
						}
					},
					fail: () => {},
					complete: () => {}
				})
			},
			edit() {
				uni.request({
					url: 'https://cx.mingmeijt.com/Api/Tax/updateTax',
					method: 'POST',
					data: {
						user_id: this.user_id,
						id: this.id,
						company_name: this.company_name,
						tax_number: this.tax_number,
						company_phone: this.company_phone,
						bank: this.bank,
						bankNumber: this.bankNumber,
						company_address: this.company_address,
						session_id: uni.getStorageSync("sessionid")
					},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => {
						if(res.data.code == 999){
							uni.navigateTo({
								url:'/pages/999/999'
							})
						};
						console.log(res)
						uni.showToast({
							title: res.data.msg
						})
						if (res.data.code == 200) {
							setTimeout(function() {
								uni.reLaunch({
									url: '../../../pages/user/user'
								})
							}, 1200);
						}
					},
					fail: () => {},
					complete: () => {}
				})
			}
		}
	}
</script>

<style>
button::after{
	border:none;
}
.top {
	margin-top: 30upx;
	background-color: #fff;
	padding: 0 20upx;
}
.uni-form-item {
	position: relative;
}
.uni-input_top {
	margin-left: 50upx;
	height: 100upx;
	line-height: 100upx;
	font-size: 40upx;
	border-bottom: 1upx solid #eee;
}
.yuan {
	position: absolute;
	top: 100upx;
	font-size: 44upx;
	font-weight: 555;
	left: 20upx;
}
.top_two {
	height: 80upx;
	line-height: 80upx;
	margin-left: 20upx;
	color: #555;
}
.top_right {
	margin-left: 50upx;
}
.foot {
	background-color: #FFFFFF;
	padding: 0 20upx;
}
.get_way {
	margin-left: 30upx;
	border-bottom: 2upx solid #eee;
}
.img {
	width: 50upx;
	height: 50upx;
	margin-left: 30upx;
	margin-top: 30upx;
}
.getit {
	position: relative;
	height: 100upx;
	border-bottom: 2upx solid #eee;
}
.getit_card {
	position: absolute;
	top: 30upx;
	left: 100upx;
}
.radio {
	position: absolute;
	top: 30upx;
	right: 25upx;
}
.show {
	background-color: #fff;
}
.same {
	height: 100upx;
	line-height: 100upx;
	display: flex;
	margin: 20upx;
	/* border-bottom: 1upx solid #eee; */
}
.name {
	flex: 1;
	line-height: 100upx;
}
.uni-input_cell {
	flex: 3;
	height: 80upx;
	margin-top: 10upx;
}
.bank {
	flex: 3;
	position: relative;
}
.bank_online {
	position: absolute;
	left: 10upx;
	top: 16upx;
}
</style>
